package myNetty.action8;

import io.netty.channel.*;

import java.io.File;
import java.io.FileInputStream;

/**
 * @author tonywang
 * @date 7/26/2018
 */
public class ZoneMemoryCopyHandler extends SimpleChannelInboundHandler{
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
        File file = new File("test.txt");
        FileInputStream fis = new FileInputStream(file);
        FileRegion region = new DefaultFileRegion(fis.getChannel(), 0, file.length());
        Channel channel = ctx.channel();
        channel.writeAndFlush(region).addListener(new ChannelFutureListener() {

            @Override
            public void operationComplete(ChannelFuture future) throws Exception {
                if(!future.isSuccess()){
                    Throwable cause = future.cause();
                    // do something
                }
            }
        });

    }
}
